<template>
  <div id="schedule">
      <div id="calzong"> 
          <Calendar :today='today' v-on:subDate='subDate' v-on:addDate='addDate'
                v-on:addMonth='addMonth'  v-on:subMonth='subMonth'></Calendar>
      </div>
      <Duanlian  :today='today'></duanlian>          
  </div>
</template>
<script>
    import {
        isLeap,
        setCalendar,
        getToday,
        errFun,
        refreshTitle,
    } from "../../tools.js";
    import Calendar from './calendar.vue';
    import Duanlian from './duanlian.vue';
    export default {
        created() {
            refreshTitle(this.$route.meta.title);
        },
        components: {
            Calendar,
            Duanlian,
        },
        data() {
            return {
                today: {
                    year: window.localStorage.year ? window.localStorage.year : getToday(new Date()).year,
                    month: window.localStorage.month ? window.localStorage.month : getToday(new Date()).month,
                    day: window.localStorage.day ? window.localStorage.day : getToday(new Date()).day,
                },
            }
        },
        computed: {
            // 需要对进入的上一级的路由进行判断
        },
        methods: {

            subDate: function() {

            },
            addDate: function() {

            },
            subMonth: function() {

            },
            addMonth: function() {

            },
            setBiaoge: function() {
                // console.log(this.today.year)
            },
            //进行日历的缩放的
            showCal() {
                var schedule = document.querySelector("#schedule");
                var calzong = document.querySelector("#calzong");
                var oldheight = document.querySelector(".calendar-wrapper").offsetHeight;
                var newheight = document.querySelector("#calzong").offsetHeight;
                var startY, endY;
                schedule.addEventListener("touchstart", function(event) {
                    startY = event.touches[0].pageY;
                })
                schedule.addEventListener("touchmove", function(event) {
                    endY = event.touches[0].pageY;
                })
                schedule.addEventListener("touchend", function(event) {
                    var scrollDistance = endY - startY;
                    if (scrollDistance < 0) {
                        //判断滚动的距离
                        if (document.body.scrollTop > 100) {
                            calzong.classList.add("active");
                            calzong.style.height = oldheight + "px";
                        }
                    } else {
                        if (document.body.scrollTop < 60) {
                            calzong.style.height = newheight + "px";
                        }
                    }
                })
            },
            // 判断上一层进来的路由
            GetNow() {
                if (this.$route.query.name == 'today' || this.$route.query.name == 'user') {
                    // 直接进入课程表的时候，应该显示的是当前的日期
                    this.today.year = getToday(new Date()).year;
                    this.today.month = getToday(new Date()).month;
                    this.today.day = getToday(new Date()).day;
                    // console.log(this.today.day)
                } else {
                    this.today.year = window.sessionStorage.year;
                    this.today.month = window.sessionStorage.month;
                    this.today.day = window.sessionStorage.day;
                }
            }

        },
        mounted() {
            this.$nextTick(function() {})
        },
        beforeDestroy() {
            // 此时的日期的记录----以便于返回的时候返回到当前的日期
            // if (this.$route.name != 'today') {
            //     if (this.$route.name != 'user') {
            // 保存当前的日期


        },
        watch: {
            today: {
                handler: function(val, oldVal) {
                    this.setBiaoge(this);
                    window.localStorage.setItem('year', this.today.year);
                    window.localStorage.setItem('month', this.today.month);
                    window.localStorage.setItem('day', this.today.day);
                },
                deep: true
            }
        },
    }
</script>
<style>
    /*#schedule {
        overflow: hidden;
    }
    
    #schedule .active {
        transition: all 0.5s;
        -webkit-transform-style: preserve-3d;
        -webkit-backface-visibility: hidden;
        overflow: hidden;
    }*/
</style>